package org.dromara.book.util;

import cn.hutool.core.util.StrUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BarCodeUtil {

    public static Integer getBarCodeNumberLength(String barCode){
        Pattern pattern = Pattern.compile("\\d+"); // 匹配连续数字的正则表达式
        Matcher matcher = pattern.matcher(barCode);

        String longestNumber = "";
        while (matcher.find()) {
            String number = matcher.group();
            if (number.length() > longestNumber.length()) {
                longestNumber = number;
            }
        }
        if (!longestNumber.isEmpty()) {
            return longestNumber.length();
        }
        return 0;
    }



    public static Long getNumber(String barCode){
        Pattern pattern = Pattern.compile("\\d+"); // 匹配连续数字的正则表达式
        Matcher matcher = pattern.matcher(barCode);

        String longestNumber = "";
        while (matcher.find()) {
            String number = matcher.group();
            if (number.length() > longestNumber.length()) {
                longestNumber = number;
            }
        }
        if (!longestNumber.isEmpty()) {
            return Long.valueOf(longestNumber);
        } else {
            return 0L;
        }
    }



    public static void main(String[] args) {
        Long szly0001 = getNumber("szly0001");
        System.out.println(StrUtil.padPre(String.valueOf(szly0001+1),4,"0"));
    }
}
